home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / archiver / unarj_st.lzh / UNARJ_ST / UNARJ230.EXE / UNARJ.H < prev   
C/C++ Source or Header  |  1991-12-04  |  12KB  |  400 lines

  1. /* UNARJ.H, UNARJ, R JUNG, 12/03/91
  2.  * Include file
  3.  * Copyright (c) 1990 by Robert K Jung.  All rights reserved.
  4.  *
  5.  *   This code may be freely used in programs that are NOT ARJ archivers
  6.  *   (both compress and extract ARJ archives).
  7.  *
  8.  *   If you wish to distribute a modified version of this program, you
  9.  *   MUST indicate that it is a modified version both in the program and
  10.  *   source code.
  11.  *
  12.  *   If you modify this program, I would appreciate a copy of the new
  13.  *   source code.  I am holding the copyright on the source code, so
  14.  *   please do not delete my name from the program files or from the
  15.  *   documentation.
  16.  *
  17.  * Modification history:
  18.  * Date      Programmer  Description of modification.
  19.  * 04/05/91  R. Jung     Rewrote code.
  20.  * 04/23/91  M. Adler    Portabilized.
  21.  * 04/29/91  R. Jung     Added volume label support.
  22.  * 05/30/91  R. Jung     Added SEEK_END definition.
  23.  * 06/03/91  R. Jung     Changed arguments in get_mode_str() and
  24.  *                       set_ftime_mode().
  25.  * 06/28/91  R. Jung     Added new HOST OS numbers.
  26.  * 07/08/91  R. Jung     Added default_case_path() and strlower().
  27.  * 07/21/91  R. Jung     Fixed #endif _QC comment.
  28.  * 08/27/91  R. Jung     Added #ifdef for COHERENT.
  29.  * 09/01/91  R. Jung     Added new host names.
  30.  * 12/03/91  R. Jung     Added BACKUP_FLAG.
  31.  *
  32.  */
  33.  
  34. #ifndef _ARH_DEF_
  35. #define _ARH_DEF_
  36.  
  37. /* Use prototypes and ANSI libraries if __STDC__ */
  38. #ifdef __STDC__
  39. #  define MODERN
  40. #endif /* __STDC__ */
  41.  
  42. /* Do not use prototypes for COHERENT */
  43. #ifdef COHERENT
  44. #  undef  MODERN
  45. #  define KEEP_WINDOW
  46. #endif /* COHERENT */
  47.  
  48. /* Use prototypes and ANSI libraries if __TURBOC__ */
  49. #ifdef __TURBOC__
  50. #  define MODERN
  51. #endif /* __TURBOC__ */
  52.  
  53. /* Use prototypes and ANSI libraries if _QC */
  54. #ifdef _QC
  55. #  define MODERN
  56. #endif /* _QC */
  57.  
  58. /* Use prototypes and ANSI libraries if _OS2 */
  59. #ifdef _OS2
  60. #  define MODERN
  61. #endif /* _OS2 */
  62.  
  63. /* Used to remove arguments in function prototypes for non-ANSI C */
  64. #ifdef MODERN
  65. #  define OF(a) a
  66. #else /* !MODERN */
  67. #  define OF(a) ()
  68. #endif /* ?MODERN */
  69.  
  70. #ifdef MODERN
  71.    typedef void voidp;
  72. #else /* !MODERN */
  73. #  define void int
  74.    typedef char voidp;
  75. #endif /* ?MODERN */
  76.  
  77. #include <stdio.h>
  78. #ifdef MODERN
  79. #  include <limits.h>
  80. #else /* !MODERN */
  81. #  ifndef UCHAR_MAX
  82. #    define UCHAR_MAX (255)
  83. #  endif
  84. #  ifndef CHAR_BIT
  85. #    define CHAR_BIT  (8)
  86. #  endif
  87. #  ifndef LONG_MAX
  88. #    define LONG_MAX  (0x7FFFFFFFL)
  89. #  endif
  90. #endif /* ?MODERN */
  91.  
  92. #ifndef SEEK_SET
  93. #  define SEEK_SET 0
  94. #endif
  95.  
  96. #ifndef SEEK_CUR
  97. #  define SEEK_CUR 1
  98. #endif
  99.  
  100. #ifndef SEEK_END
  101. #  define SEEK_END 2
  102. #endif
  103.  
  104. typedef unsigned char  uchar;   /*  8 bits or more */
  105. typedef unsigned int   uint;    /* 16 - 32 bits or more */
  106. typedef unsigned short ushort;  /* 16 bits or more */
  107. typedef unsigned long  ulong;   /* 32 bits or more */
  108.  
  109. #define USHRT_BIT   (CHAR_BIT * sizeof(ushort))
  110.  
  111. /* ********************************************************* */
  112. /* Environment definitions (implementation dependent)        */
  113. /* ********************************************************* */
  114.  
  115. #ifdef _QC
  116. #define __MSDOS__
  117. #endif
  118.  
  119. #ifdef __MSDOS__
  120. #define OS                  0
  121. #define PATH_SEPARATORS     "\\:"
  122. #define PATH_CHAR           '\\'
  123. #define MAXSFX              25000L
  124. #define ARJ_SUFFIX          ".ARJ"
  125. #endif
  126.  
  127. #ifdef _OS2
  128. #define OS                  0           /* ??? */
  129. #define PATH_SEPARATORS     "\\:"
  130. #define PATH_CHAR           '\\'
  131. #define SWITCH_CHARS        "-/"
  132. #define MAXSFX              25000L
  133. #define ARJ_SUFFIX          ".ARJ"
  134. #endif
  135.  
  136. #ifdef __CI
  137. #define PRIME               1
  138. #define OS                  1
  139. #define PATH_SEPARATORS     ">"
  140. #define PATH_CHAR           '>'
  141. #define FIX_PARITY(c)       c |= ~ASCII_MASK
  142. #define DEFAULT_DIR         "*>"
  143. #define ARJ_SUFFIX          ".ARJ"
  144. #endif
  145.  
  146. /* Error levels */
  147.  
  148. #ifndef ERROR_DEFINES
  149.  
  150. #define ERROR_OK        0       /* success */
  151. #define ERROR_WARN      1       /* minor problem (file not found) */
  152. #define ERROR_FAIL      2       /* fatal error */
  153. #define ERROR_CRC       3       /* CRC error */
  154. #define ERROR_SECURE    4       /* ARJ security invalid or not found */
  155. #define ERROR_WRITE     5       /* disk full */
  156. #define ERROR_OPEN      6       /* can't open file */
  157. #define ERROR_USER      7       /* user specified bad parameters */
  158. #define ERROR_MEMORY    8       /* not enough memory */
  159.  
  160. #endif
  161.  
  162. #ifndef MAXSFX              /* size of self-extracting prefix */
  163. #define MAXSFX              500000L
  164. #endif
  165. #ifndef FNAME_MAX
  166. #define FNAME_MAX           512
  167. #endif
  168. #ifndef SWITCH_CHARS
  169. #define SWITCH_CHARS        "-"
  170. #endif
  171. #ifndef FIX_PARITY
  172. #define FIX_PARITY(c)       c &= ASCII_MASK
  173. #endif
  174. #ifndef ARJ_SUFFIX
  175. #define ARJ_SUFFIX          ".arj"
  176. #endif
  177. #ifndef ARJ_DOT
  178. #define ARJ_DOT             '.'
  179. #endif
  180. #ifndef DEFAULT_DIR
  181. #define DEFAULT_DIR         ""
  182. #endif
  183. #ifndef OS
  184. #define OS                  2
  185. #endif
  186. #ifndef PATH_SEPARATORS
  187. #define PATH_SEPARATORS     "/"
  188. #endif
  189. #ifndef PATH_CHAR
  190. #define PATH_CHAR           '/'
  191. #endif
  192.  
  193. /* ********************************************************* */
  194. /* end of environmental defines                              */
  195. /* ********************************************************* */
  196.  
  197. /* ********************************************************* */
  198. /*
  199.  * Structure of archive block (low order byte first):
  200.  *
  201.  *  2  header id (comment and local file) = 0xEA60 or 60000U
  202.  *  2  basic header size (from 'first_hdr_size' thru 'comment' below)
  203.  *           = first_hdr_size + strlen(filename) + 1 + strlen(comment) + 1
  204.  *           = 0 if end of archive
  205.  *
  206.  *  1  first_hdr_size (size up to 'extra data')
  207.  *  1  archiver version number
  208.  *  1  minimum archiver version to extract
  209.  *  1  host OS   (0 = MSDOS, 1 = PRIMOS, 2 = UNIX, 3 = AMIGA, 4 = MAC-OS)
  210.  *               (5 = OS/2, 6 = APPLE GS, 7 = ATARI ST, 8 = NEXT)
  211.  *               (9 = VAX VMS)
  212.  *  1  arj flags (0x01 = GARBLED_FLAG, 0x02 = RESERVED)
  213.  *               (0x04 = VOLUME_FLAG,  0x08 = EXTFILE_FLAG)
  214.  *               (0x10 = PATHSYM_FLAG, 0x20 = BACKUP_FLAG)
  215.  *  1  method    (0 = stored, 1 = compressed most ... 4 compressed fastest)
  216.  *  1  file type (0 = binary, 1 = text, 2 = comment header)
  217.  *               (3 = directory, 4 = volume label)
  218.  *  1  reserved
  219.  *  4  date time stamp modified
  220.  *  4  compressed size
  221.  *  4  original size
  222.  *  4  original file's CRC
  223.  *  2  entryname position in filename
  224.  *  2  file access mode
  225.  *  2  host data
  226.  *  ?  extra data
  227.  *     4 bytes for extended file position
  228.  *
  229.  *  ?  filename (null-terminated)
  230.  *  ?  comment  (null-terminated)
  231.  *
  232.  *  4  basic header CRC
  233.  *
  234.  *  2  1st extended header size (0 if none)
  235.  *  ?  1st extended header
  236.  *  4  1st extended header's CRC (not present if 0 extended header size)
  237.  *  ...
  238.  *  ?  compressed file
  239.  *
  240.  * ********************************************************* */
  241.  
  242. /* ********************************************************* */
  243. /*                                                           */
  244. /*     Time stamp format:                                    */
  245. /*                                                           */
  246. /*      31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16      */
  247. /*     |<---- year-1980 --->|<- month ->|<--- day ---->|     */
  248. /*                                                           */
  249. /*      15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0      */
  250. /*     |<--- hour --->|<---- minute --->|<- second/2 ->|     */
  251. /*                                                           */
  252. /* ********************************************************* */
  253.  
  254. #define CODE_BIT          16
  255.  
  256. #define NULL_CHAR       '\0'
  257. #define MAXMETHOD          4
  258.  
  259. #define ARJ_VERSION        3
  260. #define ARJ_X_VERSION      3    /* decoder version */
  261. #define ARJ_X1_VERSION     1
  262. #define DEFAULT_METHOD     1
  263. #define DEFAULT_TYPE       0    /* if type_sw is selected */
  264. #define HEADER_ID     0xEA60
  265. #define HEADER_ID_HI    0xEA
  266. #define HEADER_ID_LO    0x60
  267. #define FIRST_HDR_SIZE    30
  268. #define FIRST_HDR_SIZE_V  34
  269. #define COMMENT_MAX     2048
  270. #define HEADERSIZE_MAX   (FIRST_HDR_SIZE + 10 + FNAME_MAX + COMMENT_MAX)
  271. #define BINARY_TYPE        0    /* This must line up with binary/text strings */
  272. #define TEXT_TYPE          1
  273. #define COMMENT_TYPE       2
  274. #define DIR_TY